package com.moore.controller;

import com.moore.dto.ResponseData;
import com.moore.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/like")
public class LikeController {
    @Autowired
    private LikeService likeService;

    @GetMapping("/add")
    public ResponseData addLike(Long communityId, Long candidateId){
        int result = likeService.addLike(communityId,candidateId);
        if (result > 0) return ResponseData.ok("点赞成功");
        return ResponseData.error("点赞失败");
    }

    @GetMapping("/addCommentLike")
    public ResponseData addCommentLike(Long communityId, Long commentId, Long candidateId){
        int result = likeService.addCommentLike(communityId,commentId,candidateId);
        if (result > 0) return ResponseData.ok("点赞成功");
        return ResponseData.error("点赞失败");
    }

    @GetMapping("/delete")
    public ResponseData deleteLike(Long communityId, Long candidateId){
        int result = likeService.deleteLike(communityId,candidateId);
        if (result > 0) return ResponseData.ok("取消点赞成功");
        return ResponseData.error("取消点赞失败");
    }

    @GetMapping("/deleteCommentLike")
    public ResponseData deleteCommentLike(Long communityId, Long commentId, Long candidateId){
        int result = likeService.deleteCommentLike(communityId,commentId,candidateId);
        if (result > 0) return ResponseData.ok("取消点赞成功");
        return ResponseData.error("取消点赞失败");
    }

}
